{ TDataField }

function TDataField.GetValue: String;
begin
  Result:=FData.Value;
end;

procedure TDataField.SetValue(AValue: String);
begin
  Normalize(AValue);
  FData.Value:=AValue;
end;

procedure TDataField.SetWidget(AValue: TWinControl);
begin
if AValue = Nil then Exit;
FData.FWidget:=AValue;
case FData.FWidget.ToString of
  'TMaskEdit':TMaskEdit(FData.FWidget).EditMask:=FEditMask;
  'TComboBox':TComboBox(FData.FWidget).Items.Assign(FPiClist);
  'TDateEdit':TDateEdit(FData.FWidget).DateOrder:=doDMY;
end;
    FData.SetValue(FData.FValue);
end;

constructor TDataField.Create(AName, ACAption: String; AType: TBaseFieldType);
begin
  inherited Create(AName, ACAption, AType);
  FData.Create;
end;

constructor TDataField.Create(AName, ACAption: String;
  Pattern: TFieldDescPattern);
begin
  inherited Create(AName, ACAption, Pattern);
  FData.Create;
end;

destructor TDataField.Destroy;
begin
  FData.Free;
  inherited Destroy;
end;

function TDataField.Validate(var Couse: string): Boolean;
begin
     Result:=inherited ValidateEditMask(FData.Value,Couse);
  if Result Then
     Result:=inherited Validate(FData.FValue,Couse);
end;

function TDataField.ToXMLString: String;
begin
  Result:=inherited ToXMLString(FData.FValue);
end;

function TDataField.ToXMLNode(const XMLDoc: TXMLDocument): TDOMElement;
begin
  Result:=inherited ToXMLNode(XMLDoc,FData.FValue);
end;

function TDataField.ToSQLString: String;
begin
  Result:=inherited ToSQLString(FData.FValue);
end;

procedure TDataField.FromXMLNode(Node: TDOMElement);
begin
  FData.FValue:=inherited FromXMLNode(Node);
end;

procedure TDataField.FromSQLFildVAlue(const SQLVAlue: TDataSetField);
begin
  FData.FValue:=inherited FromSQLFildVAlue(SQLVAlue);
end;

{ TFieldData }

function TFieldData.GetValue:String;
begin
if FWidget<>nil then
case FWidget.ToString of
  'TEdit':FValue:=TEdit(FWidget).Text;
  'TMaskEdit':FValue:=TMaskEdit(FWidget).Text;
//  'TLabel':FValue:=TLabel(FWidget).Caption;
  'TMemo':FValue:=TMemo(FWidget).Text;
  'TComboBox':FValue:=TComboBox(FWidget).Text;
  'TDateEdit':FValue:=DateToStr(TDateEdit(FWidget).Date,LocalFormatSettings);
end;
  Result:=FValue;
end;

procedure TFieldData.SetValue(AValue:String);
var
  I:Integer;
begin
if FWidget<>nil then
   case FWidget.ToString of
     'TEdit':TEdit(FWidget).Text:=AValue;
     'TMaskEdit':TMaskEdit(FWidget).Text:=AValue;
     //TLabel:TLabel(FWidget).Caption:=AValue;
     'TMemo':TMemo(FWidget).Text:=AValue;
     'TComboBox':
       begin
         if TComboBox(FWidget).Items.Count = 0 then
           begin
             TComboBox(FWidget).Items.Add(AValue);
             TComboBox(FWidget).ItemIndex:=0;
           end
         else
           begin
             I:=TComboBox(FWidget).Items.IndexOf(AValue);
             {$IFDEF DEBUG}
             if I<0 then Raise ETransferObjFildError.Create(fstrUnknounComboBoxValue,Format(fstrUnknounComboBoxValueContext,[FWidget.Name,FWidget.Owner.Name,AValue]),nil)
             else
              TComboBox(FWidget).ItemIndex:=I;
             {$ELE}
              TComboBox(FWidget).Text:=AValue;
             {$ENDIF}
           end;
       end;
     'TDateEdit':TDateEdit(FWidget).Text:=AValue;
   end;
if FValue<> AValue then
   FValue:=AValue;
end;

procedure TFieldData.SetWidget(AWidget: TWinControl);
begin
     If IsWidgetClass(AWidget) and (TClass(AWidget).ClassType<> TStringGrid) and (TClass(AWidget).ClassType<> TLabel) then
       begin
        FWidget.Assign(AWidget);
        SetValue(FValue);
       end
     Else
       Raise Exception.Create('Illegal FieldWidget ['+AWidget.ToString+']');
end;

